<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>STAT HUB - 健康检查</title>
    <link href="stylesheets/stat.css" rel="stylesheet" type="text/css" />
    <script src="js/jquery-3.3.1.min.js" type="text/javascript"></script>
    <script src="js/common.js" type="text/javascript"></script>
    <script>
        $(document).ready(function () {
            var pid = get_param('pid').pid.replace('#', '');
            $('#tailHeader').text('Health check log of pid #' + pid + ': ');
            setInterval(function() {
                log_out(pid);
            }, 1000);
        });
        
        function log_out(pid) {
            $.get('/v1/proc/' + pid + '/_health', function(lines, status, xhr) {
                $.each(lines, function(i, line) {
                    //alert(line);
                    var time = new Date(line.time);
                    var ok = line.ok ? '<font color="green">OK</font>' : '<font color="red">ERROR</font>';
                    var endpoint = line.endpoint;
                    var msg = line.message ? line.message : '';
                    var code = line.code;
                    var respTime = line.responseTime;
                    $('#tailbody').append('' + time + ' [' + endpoint + '] ' + code + ' - ' + ok + '  (' + respTime + ' ms) ' + msg + '<br/>');
                });
                if (lines.length > 0) {
                    $("html, body").animate({ scrollTop: $(document).height() }, "slow");
                }
            });
        }
    </script>
</head>
<body>
    <div id="tailHeader"></div>
    <div id="tailbody"></div>
</div>
</body>
</html>
